package com.chixing.controller;

import com.chixing.pojo.Member;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class RestfulDemoController {

    //GET http://localhost:8080/mymember
    @GetMapping("mymember")
    public List<Member> getAll(){
        Member member = new Member();
        member.setMemberId(1066);
        member.setMemberName("张富贵");
        member.setMemberTelno(19388847775L);

        Member member1 = new Member();
        member.setMemberId(1066);
        member.setMemberName("张富贵");
        member.setMemberTelno(19388847775L);

        List<Member> memberList = new ArrayList<>();
        memberList.add(member);
        memberList.add(member1);

        return memberList;
    }



    //GET  http://localhost:8080/mymember/1011
    @GetMapping("mymember/{id}")  //@RequestMapping(method = RequestMethod.GET)
    public Member getById(@PathVariable("id") Integer memberId){  // memberId = id = 1011
        Member member = new Member();
        member.setMemberId(memberId);
        member.setMemberName("张富贵");
        member.setMemberTelno(19388847775L);
        return member;

    }

    //POST http://localhost:8080/mymember
    @PostMapping("mymember")
    public boolean save(Member member){
        System.out.println(member);
        return true;
    }

    //DELETE http://localhost:8080/mymember/1011
    @DeleteMapping("mymember/{id}")
    public boolean delete(@PathVariable("id") Integer memberId){
        System.out.println("delete id:"+memberId);
        return true;
    }

}
